package lmycc.test.demo.service;

import lmycc.test.demo.domain.Student;
import lmycc.test.demo.repository.LoginRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
@Component
public class LoginService {

    @Autowired
    private LoginRepository loginRepository;

    /**
     * selectAll方法
     */
    public List<Student> selectAll() {
        return loginRepository.findAll();
    }

    /**
     * insert方法
     *
     * @param student
     */
    public void insertOne(Student student) {
        loginRepository.save(student);
    }

    /**
     * update方法
     */
    public void resetPwd(Student student) {
        System.out.println(student.getPassword() + student.getName());
        loginRepository.resetPwd(student.getName(), student.getPassword());
    }

    public Student login(Student student) {
        return loginRepository.findByNameAndPassword(student.getName(), student.getPassword());
    }

    public List<Student> findByName(String name) {
        return loginRepository.findByName(name);
    }

}
